<?php
/**
* 공통헤더
* /common/inc.header.php
* 2008-05-06
* hamhaja <hamhaja@nextez.co.kr>
*/
session_start();

header("content-type:text/html; charset=utf-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

require_once dirname(__FILE__) . '/application.php';
$App = new Application();

session_cache_limiter('private');
ini_set("session.cookie_lifetime", "86400");
ini_set("session.cache_expire", "86400");
ini_set("session.gc_maxlifetime", "86400");

$lang = "vn";

if (isset($_GET["lang"])) {
    $lang = $_GET["lang"];
    $_SESSION['language'] = $lang;
}
else if (isset($_SESSION['language'])) {
	$lang = $_SESSION['language'];
}


if ($lang == "ko") require_once dirname(__FILE__)."\Locale\ko.php";
else if ($lang == "en") require_once dirname(__FILE__)."\Locale\en.php";
else if ($lang == "vn") require_once dirname(__FILE__)."\Locale\\vn.php";
else require_once dirname(__FILE__)."\Locale\ko.php";


/*****************************************************************************
* 실행시간체크 시작
*****************************************************************************/
if ($App->is_debug())
{
	list($usec, $sec) = explode(" ", microtime());
	$g_start_time = ((float)$usec + (float)$sec);
}

/*****************************************************************************
* 메세지 및 모듈 파일 요청
*****************************************************************************/

require_once $App->_dir_lib . '/message/inc.error.php';
require_once $App->_dir_lib . '/message/inc.success.php';
/*****************************************************************************
* Database Connect
*****************************************************************************/
$App->class_require('Mysql');
$Db = new Mysql();
if ($Db->connect($App->_db_host, $App->_db_user, $App->_db_pass)) $Db->select_db($App->_db_name);
else $Db->error();




/*****************************************************************************
* Utility Class
*****************************************************************************/
$App->class_require('Array2');
$App->class_require('Html');
$App->class_require('JavaScript');
$App->class_require('String');
$App->class_require('Array2');
$App->class_require('Error');
$App->class_require('Success');
$App->class_require('XSSFilter');
$App->class_require('User');

$Array		= new Array2();
$Html		= new Html();
$Script		= new JavaScript();
$String		= new String();
$Array		= new Array2();
$Error		= new Error();
$Success	= new Success();
$XSSFilter	= new XSSFilter();
$User		= new User();

//$session_name = strtoupper(str_replace('.'. $App->_site_domain, '', $_SERVER['HTTP_HOST']));
$session_name = strtoupper(substr($App->_site_domain, 0, strpos($App->_site_domain, '.')));

// set init
$g_stylesheet = array();
$g_javascript = array();

// set title
$g_title[] = $App->_site_name;


//바로 사이트 주소로 들어오는경우
if(!$_SESSION['g_site'] && !$_GET['g_site'])
{
	$site_check = explode("/",$_SERVER['PHP_SELF']);

	$_GET['g_site'] = $site_check [2];
	$_GET['g_lang'] = $site_check [3];

}

//사이트 도메인 체크
if($_GET['g_site']) $_SESSION['g_site']['id'] = $_GET['g_site'];
if($_GET['g_lang']) $_SESSION['g_lang'] = $_GET['g_lang'];




$g_site_domain =  $_SESSION['g_site']['id'];


function g_menu_firewall(&$menus)
{
	global $User;
	$user_level = $User->is_login() ? $User->get_level() : $User->get_default_level();

	foreach ($menus as $k => $v)
	{
		if ($v['levels'])
		{
			$levels = split(',', $v['levels']);
			if (!in_array($user_level, $levels))
			{
				unset($menus[$k]);
				continue;
			}
		}

		if ($v['childs'])
		{
			g_menu_firewall($menus[$k]['childs']);
			if (!count($menus[$k]['childs'])) unset($menus[$k]);
		}
	}
	reset($menus);
}
?>